package wolftrace_company.study_android_ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import java.util.ArrayList;
import java.util.List;

import wolftrace_company.study_android_ui.R;
import wolftrace_company.study_android_ui.fragment.FragMentA;
import wolftrace_company.study_android_ui.fragment.FragMentB;
import wolftrace_company.study_android_ui.fragment.FragMentC;
import wolftrace_company.study_android_ui.viewpage.ViewPagerAdapter;

/**
 * Created by SimpleTonOne on 2018/3/31.
 */

public class ShowViewPagerActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener,View.OnClickListener {
    private List<Fragment> list;
    private ViewPagerAdapter viewPagerAdapter;
    private ViewPager viewPager;
    private Button button1;
    private Button button2;
    private Button button3;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setContentView(R.layout.showviewpage);
        viewPager = findViewById(R.id.sViewPager);
        viewPager.setOnPageChangeListener(this);
        list = new ArrayList<>();
        list.add(new FragMentA());
        list.add(new FragMentB());
        list.add(new FragMentC());
        viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(),list);
        viewPager.setAdapter(viewPagerAdapter);
        viewPager.setCurrentItem(0);
        button1 = findViewById(R.id.s_btn_1);
        button2 = findViewById(R.id.s_btn_2);
        button3 = findViewById(R.id.s_btn_3);
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        switch (position){
            case 0:
                break;
            case 1:
                break;
            case 2:
                break;
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.s_btn_1:
                viewPager.setCurrentItem(0);
                break;
            case R.id.s_btn_2:
                viewPager.setCurrentItem(1);
                break;
            case R.id.s_btn_3:
                viewPager.setCurrentItem(2);
                break;
        }
    }
}

